package org.redxentertainment.videomanager;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CategoryAdapter extends ArrayAdapter<Category>{
	public ArrayList<Category> 	categories;
	
	public CategoryAdapter(Context context, int textViewResourceId, ArrayList<Category> categories) {
        super(context, textViewResourceId, categories);
        this.categories = categories;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
	        View view = convertView;
	        
	        if (view == null) {
	        	Context context = getContext();
	            LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	            view = vi.inflate(R.layout.category, null);
	        }
	        Category category = categories.get(position);
	        
	        if(category != null) {
	        	TextView title 	= (TextView) view.findViewById(R.id.title);
                TextView desc 	= (TextView) view.findViewById(R.id.description);
                ImageView icon 	= (ImageView) view.findViewById(R.id.icon);
                
                if(category.name.compareTo("video") != 0 && category.name.compareTo("<unknown>") != 0 ) {
                	title.setText(category.name);
                } else {
                	title.setText("Uncategorized");
                }
                
                if(category.thumbnail != null) {
                	icon.setImageBitmap(category.thumbnail);
                } else {
                	/*
                	if( category.name.compareTo("Camera") == 0 ) {
                		icon.setImageResource(R.drawable.camera);
                	} else {
                	*/
                		icon.setImageResource(R.drawable.allvids);	
                	//}
                }
                
                desc.setText(category.videos + " Videos");
	        }	        
	        
	        return view;
	}
}
